﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public partial class index : System.Web.UI.Page
{
    public int tjbId;
    public int grjjId;
    public int jxxdId;
    public int hjzsId;
    public int jylwId;
    public int cbjcId;
    public int kycgId;
    public int fmzlId;
    public int lxfsId;
    public int xmclId;
    public int kylwId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //当数据库是本地数据库的时候，获取学校要闻新闻
            object dtnew = BindData("select top 8 n_id,n_Title from tb_News where n_Category='新闻动态' order by n_id DESC");
            Repeater1.DataSource = dtnew;
            Repeater1.DataBind();

            tjbId = GetTopId("推荐表");
            grjjId = GetTopId("个人简介");
            jxxdId = GetTopId("教学心得");
            hjzsId = GetTopId("获奖证书");
            jylwId = GetTopId("教研论文");
            cbjcId = GetTopId("出版教材");
            kycgId = GetTopId("科研成果");
            fmzlId = GetTopId("发明专利");
            lxfsId = GetTopId("联系方式");
            xmclId = GetTopId("项目材料");
            kylwId = GetTopId("科研论文");

        }

    }

    //当数据库是本地数据库的时候
    protected object BindData(string sql)
    {
        string sqlSelect = sql;
        DataTable dt = new DataTable();
        dt = OleDbHelper.GetDataTable(sqlSelect);
        return dt;
    }

    //取出一条最新数据GetTopId
    protected int GetTopId(string category)
    {
        int TopId = 1;
        string sqlSelect = "select top 1 n_id from tb_News where n_category=@category";
        OleDbParameter[] para = {
                                    new OleDbParameter("@category",category)
                                };
        OleDbDataReader dr = OleDbHelper.GetDataReader(sqlSelect, para);
        if (dr.HasRows)
        {
            if (dr.Read())
            {
                TopId = Convert.ToInt32(dr["n_id"].ToString().Trim());
            }
            dr.Close();
            dr.Dispose();
        }
        else
        {
            TopId = 111111;
            //Response.Write("<script>alert('暂无资料');window.top.location='index.aspx';</script>");
        }
        return TopId;
    }
}